package com.gjzhao.fmmall.controller;

import com.gjzhao.fmmall.service.UserRegisterService;
import com.gjzhao.fmmall.vo.RespResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 用户注册 Controller
 * @Author: gjzhao
 * @Date Created in 2022-02-12 11:06 下午
 */
@RestController
@RequestMapping("/user")
@CrossOrigin //处理前后端跨域问题：由于前端和后端使用的protocol、ip、port的不一致造成跨域访问，数据不能正常响应
@Api(value = "用户管理的接口", tags = "用户管理-注册用户")
public class UserRegisterController extends BaseController {

    @Autowired
    private UserRegisterService registerService;

    @PostMapping(value = "/register")
    @ApiOperation(value = "注册用户")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "用户名", name = "username", dataType = "string", required = true),
        @ApiImplicitParam(value = "密码", name = "password", dataType = "string", required = true)
    })
    public RespResultVO addUser(String username, String password) {
        return registerService.insert(username, password);
    }
}
